{% load emojificate humanize i18n package_tags typogrify_tags waffle_tags %}


{% switch "switch_use_grid_of_the_week" %}
    <div class="container">
        <div class="row">
            {% include "homepage/grid_of_the_week_partial.html" %}
            {% include "homepage/django_package_of_the_week_partial.html" %}
            {% switch "switch_use_psa" %}
                {% include "homepage/public_service_announcement_partial.html" %}
            {% endswitch %}
        </div>
    </div>
{% endswitch %}


{% comment %}
TODO: Fix this hack
This is a hack to keep the next set of divs from wrapping up and making the display look funny
{% endcomment %}

<div class="container">
    <div class="row">
    </div>
</div>


<div class="container">
    <div class="grid grid-cols-1 gap-6 py-5 md:grid-cols-3 lg:grid-cols-5">
        <!-- start Categories panel -->
        {% for category in categories %}
            {% if category.package_count %}
                <div class="text-center categories">
                    <h2 class="panel-title">{{ category.title_plural }} </h2>
                    <p>{{ category.description|widont }}</p>
                    <a href="{% url 'category' category.slug %}" class="btn btn-primary">Show {{ category.title_plural }} ({{ category.package_count|intcomma }})</a>
                </div>
            {% endif %}
        {% endfor %}
        <!-- end Categories panel -->
    </div>
</div>


<div class="container">
    <div class="row">
        <!-- start python releases -->
        <div class="col-sm-4 col-lg-4">
            <h2>{% translate "Latest Python Package Releases" %}</h2>

            <div class="list-group">
                {% for version in latest_python3 %}
                    <a href="{{ version.package.get_absolute_url }}" class="list-group-item">
                        <h4 class="list-group-item-heading">
                            {{ version.package.title }}
                            <small>v{{ version.number }}</small>
                        </h4>
                        <p class="list-group-item-text line-clamp-3 wrap-break-word">
                            {% with short=version.package.repo_description|truncatewords:25 %}
                                {% if version.package.repo_description|length > short|length %}
                                    {{ short|slice:"-3"|widont }}...
                                {% else %}
                                    {{ short|widont }}
                                {% endif %}
                            {% endwith %}
                        </p>
                    </a>
                {% endfor %}
            </div>

            {% comment %}
            <div><a href="{% url "py3_compat" %}">View more</a></div>
            {% endcomment %}
        </div>
        <!-- end python releases -->

        <!-- start latest five packages -->
        <div class="col-sm-4 col-lg-4">
            <h2>{% translate "Latest Five Packages Added" %}</h2>

            <div class="list-group">
                {% for package in latest_packages %}
                    <a href="{{ package.get_absolute_url }}" class="list-group-item">
                        <h4 class="list-group-item-heading">
                            {{ package.title|emojify|emojificate }}
                            {% if package.pypi_version %}<small>v{{ package.pypi_version }}</small>{% endif %}
                        </h4>
                        <p class="list-group-item-text line-clamp-3 wrap-break-word">
                            {% with short=package.repo_description|truncatewords:25 %}
                                {% if package.repo_description|length > short|length %}
                                    {{ short|slice:"-3" }}...
                                {% else %}
                                    {{ short }}
                                {% endif %}
                            {% endwith %}
                        </p>
                    </a>
                {% endfor %}
                <a href="{% url 'latest_packages' %}" class="btn btn-primary btn-block-display">View More</a>
            </div>

            {% comment %}
            <div><a href="{% url "latest_packages" %}">View more</a></div>
            {% endcomment %}
        </div>
        <!-- end latest five packages -->

        <!-- most favorite packages -->
        <div class="col-sm-4 col-lg-4">
            <h2>{% translate "Most Liked Packages" %}</h2>

            <div class="list-group">
                {% for package in most_liked_packages %}
                    <a href="{{ package.get_absolute_url }}" class="list-group-item">
                        <h4 class="list-group-item-heading">
                            {{ package.title|emojify|emojificate }}
                            {% if package.pypi_version %}<small>v{{ package.pypi_version }}</small>{% endif %}
                        </h4>
                        <p class="list-group-item-text line-clamp-3 wrap-break-word">
                            {% with short=package.repo_description|truncatewords:25 %}
                                {% if package.repo_description|length > short|length %}
                                    {{ short|slice:"-3" }}...
                                {% else %}
                                    {{ short }}
                                {% endif %}
                            {% endwith %}
                        </p>
                    </a>
                {% endfor %}
                <a href="{% url 'liked_packages' %}" class="btn btn-primary btn-block-display">View More</a>
            </div>


        </div>

        <!-- end most favorite packages -->

        <!-- start five random packages -->
        <div class="col-sm-4 col-lg-4">
            <h2>{% translate "Random Five Packages" %}</h2>

            <div class="list-group">
                {% for package in random_packages %}
                    <a href="{{ package.get_absolute_url }}" class="list-group-item">
                        <h4 class="list-group-item-heading">
                            {{ package.title|emojify|emojificate }}
                            {% if package.pypi_version %}<small>v{{ package.pypi_version }}</small>{% endif %}
                        </h4>
                        <p class="list-group-item-text line-clamp-3 wrap-break-word">
                            {% with short=package.repo_description|truncatewords:25 %}
                                {% if package.repo_description|length > short|length %}
                                    {{ short|slice:"-3" }}...
                                {% else %}
                                    {{ short }}
                                {% endif %}
                            {% endwith %}
                        </p>
                    </a>
                {% endfor %}
            </div>

            {% comment %}
            <div><a href="{% url "latest_packages" %}">View more</a></div>
            {% endcomment %}
        </div>
        <!-- end five random packages -->

    </div>

</div>
